package com.itheima.stock.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.stock.common.domian.StockUpdownDomain;
import com.itheima.stock.service.Stock_rtService;
import com.itheima.stock.vo.resp.PageResult;
import com.itheima.stock.vo.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author: siwukun
 * @date: 2022/06/01
 * @description: 涨幅榜
 */

@RestController
@RequestMapping("/api/quot/stock")
public class Stock_rtController {

    @Autowired
    private Stock_rtService service;

    /**
     * 涨幅榜
     *
     * @return
     */
    @GetMapping("/increase")
    public R<List<StockUpdownDomain>> selectAllStock() {

        return service.queryAllStock_rt();

    }

    /**
     * 分页查询
     *
     * @return
     */
    @GetMapping("/all")
    public R<PageResult<PageInfo>> selctAllPageStockUpdown(@RequestParam("page") Integer page,
                                                           @RequestParam("pageSize") Integer pageSize
    ) {

        return service.queryAllPageStockUpdown(page, pageSize);
    }

    /**
     * 涨停数据
     *
     * @return
     */
    @GetMapping("/updown/count")
    public R<Map<String, List>> selectAllUpDown() {
        return service.queryAllUpDown();
    }

    /**
     * 下载文件
     *
     * @param page     当前页
     * @param pageSize 没页大小
     * @param response 响应处理
     */
    @GetMapping("/export")
    public void excelDownload(@RequestParam("page") Integer page,
                              @RequestParam("pageSize") Integer pageSize,
                              HttpServletResponse response) {

        service.queryAllStock_rtToExcel(page,pageSize,response);
    }

}
